package com.navi.loaddata.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class SqlUtil {

    public static String set2InCondition(Set<String> mySet,String column) {
        StringBuffer inSb = new StringBuffer();

        if (!mySet.isEmpty()) {
            if(mySet.size()<1000){
                mySet.forEach(s -> inSb.append("'").append(s).append("',"));
            }else{
                List<String> list = new ArrayList<String>();
                inSb.append(column+" in(");
                list.addAll(mySet);
                for(int i=0;i<list.size();i++){
                    inSb.append("'").append(list.get(i)).append("',");
                    if(i>=500 && i % 500 == 0 && i!=list.size()-1){
                        inSb.deleteCharAt(inSb.length()-1);
                        inSb.append(") or  ").append(column+" in(");
                    }
                    if(i == list.size()-1){
                        inSb.deleteCharAt(inSb.length()-1);
                        inSb.append(" )  ");

                    }

                }

            }

            return inSb.substring(0, inSb.length() - 1);
        } else {
            return "";
        }
    }

    public static void main(String[] args) {
        Set<String> glassSet = ConcurrentHashMap.newKeySet();
        glassSet.add("123");
//        glassSet.add("1we");
//        glassSet.add("asd");
//        glassSet.add("uuu");
        System.out.println(set2InCondition(glassSet,null));
    }
}
